package NumSort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.UUID;

public class NumSortMap extends Mapper<LongWritable, Text, NumSortBean, NumSortBean> {
    //提升为全局变量，避免每次执行map方法都执行此操作
    final NumSortBean sortBean = new NumSortBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1 读取一行文本，转为字符串，切分
        final String[] fields = value.toString().split("\t");
        final String Rm_str = getUUID() + fields[0];
        //2 解析出各个字段封装成SpeakBean对象
        sortBean.setNumxh(Long.valueOf(fields[0]));
        sortBean.setNumRm(Rm_str);
        System.out.println("Map方法被执行。。。key--- " + sortBean.getNumxh() + "。。。Number---" + sortBean.getNumRm());
        //3 NumBean作为key输出
        context.write(sortBean, sortBean);
    }

    //获得UUID
    public static String getUUID() {
        return UUID.randomUUID().toString();
    }

}